package com.base.config;

import org.springframework.boot.autoconfigure.web.servlet.error.ErrorViewResolver;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

@Component
public class OpenErrorViewResolver implements ErrorViewResolver {

    @Override
    public ModelAndView resolveErrorView(HttpServletRequest request, HttpStatus status, Map<String, Object> model) {
        if("404".equals(String.valueOf(status))){
            return new ModelAndView("/error/page_404");
        }else if("403".equals(String.valueOf(status))){
            return new ModelAndView("/error/page_403");
        }else if("500".equals(String.valueOf(status))){
            return new ModelAndView("/error/page_500");
        }else{
            return new ModelAndView("/error/page_404");
        }
    }
}
